<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Point_log_entity{
	var $current_dbprefix = "";
	var $CI;
	var $id = 0;
	var $escort_id = 0;
	var $current_point = 0;
	var $amount = 0;
	var $action = "";
	var $description = "";
	var $datetime = "";
	var $site_ref = "";
	
	function __construct() {
		$this->CI= & get_instance();
		$this->current_dbprefix = $this->CI->db->dbprefix;
		$this->CI->db->set_dbprefix('default_');
	}
	function __destruct() {
		$this->CI->db->set_dbprefix($this->current_dbprefix);
	}
    
	function init($cmd, $input)
	{
		$this->CI->db->set_dbprefix('default_');
		if($cmd == 'id')
		{
			$result = $this->CI->db->where('id',$input)->get(TBL_POINT_LOG)->result();
		}
		else
		{
			return false;
		}
		
		if( !empty($result) )
		{
			$this->id = $result[0]->id;
			$this->escort_id = $result[0]->escort_id;
			$this->amount = $result[0]->amount;
			$this->action = $result[0]->action;
			$this->description = $result[0]->description;
			$this->current_point = $result[0]->current_point;
			$this->datetime = $result[0]->datetime;
			$this->site_ref = $result[0]->site_ref;
			
			return $this;
		}
		return false;
	}
	
	function setAction($input){ $this->action=$input; }
	function setEscortId($input){ $this->escort_id=$input; }
	function setAmount($input){ $this->amount=$input; }
	function setCurrentPoint($input){ $this->current_point=$input; }
	function setDateTime($input){ $this->datetime=$input; }
	function setSiteRef($input){ $this->site_ref=$input; }
	function setDescription($input){ $this->description=$input; }
	
	function getId(){ return $this->id; }
	function getAction(){ return $this->action; }
	function getEscortId(){return $this->escort_id; }
	function getAmount(){return $this->amount; }
	function getDescription(){return $this->description; }
	function getSiteRef(){return $this->site_ref; }
	function getDateTime(){return $this->datetime; }
	function getCurrentPoint(){return $this->current_point; }
	
	function update()
	{
		$this->CI->db->set_dbprefix('default_');
		$this->CI->db->set('action', $this->action);
		$this->CI->db->set('escort_id', $this->escort_id);
		$this->CI->db->set('amount', $this->amount);
		$this->CI->db->set('description', $this->description);
		$this->CI->db->set('site_ref', $this->site_ref);
		$this->CI->db->set('current_point', $this->current_point);
		
		$this->CI->db->where('id', $this->id)->update(TBL_POINT_LOG);
	}
	
	function createNewEntity(){
		$this->CI->db->set_dbprefix('default_');
		$this->CI->db->set('datetime', time());
		$this->CI->db->insert(TBL_POINT_LOG);
		
		return $this->init('id',$this->CI->db->insert_id());
	}
	
	
	//end class
}
